<%@ page import="com.the8thfold.anton.users.Roles; org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils; com.the8thfold.anton.ant.JobStatus; org.apache.tools.ant.Target" contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>View Job</title>
    <meta name="layout" content="main" />

</head>
<body>

<div>
    <table style="border: none;">
        <tr>
            <td width="1%"><h1>Job:</h1></td>
            <td>
                <g:if test="${SpringSecurityUtils.ifAllGranted(Roles.ROLE_JOB_ADMIN.toString())}">
                    <g:formRemote onSuccess="jQuery('#${job.jobId}_name').effect('highlight',{color: '#90ee90'},1000);" name="f2" url="[controller: 'job', action: 'updateField', id: job.jobId]">
                        <g:hiddenField name="field" value="name"/>
                        <input id="${job.jobId}_name" class="ui-corner-all" type="text" name="value" value="${job.name}" style="width: 50%;"/>
                        <a href="javascript: void();" onclick="jQuery('#f2').submit();" name="submit" value="" href="#" class="btn save" icon="ui-icon-disk"></a>
                    </g:formRemote>
                </g:if>
                <g:else>${job.name}</g:else>
            </td>
        </tr>
    </table>
    <hr/>
    <br/>
    <span><b>State:</b> ${job.jobStatus}</span>
    <g:if test="${SpringSecurityUtils.ifAllGranted(Roles.ROLE_JOB_ADMIN.toString())}">
        <g:if test="${job.isActive()}">
            ( <a class="" href="${createLink(controller: 'job', action: 'pause', id: job.jobId, params: [origin: request.forwardURI.toString().decodeURL()])}">Pause</a> )
        </g:if>
        <g:else>
            ( <a class="" href="${createLink(controller: 'job', action: 'activate', id: job.jobId, params: [origin: request.forwardURI.toString().decodeURL()])}">Activate</a> }
        </g:else>
    </g:if>
    |
    <span title="${job.dateCreated}"><b>Created By: </b>
        ${job.createdBy.firstName + " " + job.createdBy.lastName} (<prettytime:display date="${job.dateCreated}" />)
    </span>
    <div class="css_right toolbar">
        <a class="btn-text" href="${createLink(controller: 'result', action: 'list', params: [jobId: job.jobId])}">View Runs <i>(${job.runResults?.size()})</i></a>
        <button ${job.isActive() ?: 'disabled=true'} class="btn-text" onclick="document.location.href='${createLink(controller: 'job', action: 'run', id: job.jobId)}'">Run Job</button>
        <g:if test="${SpringSecurityUtils.ifAllGranted(Roles.ROLE_SCRIPT_ADMIN.toString())}">
            <a class="btn-text" href="${createLink(controller: 'script', action: 'view', id: job.script.scriptId)}">View Script</a>
        </g:if>
        <g:if test="${SpringSecurityUtils.ifAllGranted(Roles.ROLE_JOB_ADMIN.toString())}">
            <a class="btn-text" href="${createLink(controller: 'job', action: 'delete', id: job.jobId)}" onclick="return confirm('Are you sure?');">Delete</a>
        </g:if>
    </div>
    <br/>
    <br/>
    <h2>Description</h2>
    <div>
        <div style="vertical-align: middle;" class="ui-widget">
            <g:if test="${SpringSecurityUtils.ifAllGranted(Roles.ROLE_JOB_ADMIN.toString())}">
                <g:formRemote onSuccess="jQuery('#${job.jobId}_description').effect('highlight',{color: '#90ee90'},1000);" name="f1" url="[controller: 'job', action: 'updateField', id: job.jobId]">
                    <g:hiddenField name="field" value="description"/>
                    <input id="${job.jobId}_description" class="ui-corner-all" type="text" name="value" value="${job.description}" style="width: 50%;"/>
                    <a href="javascript: void();" onclick="jQuery('#f1').submit();" name="submit" value="" href="#" class="btn save" icon="ui-icon-disk"></a>
                </g:formRemote>
            </g:if><g:else>${job.description}</g:else>
        </div>
    </div>
    <br/>
    <h2>Run type</h2>
    <div>
        <g:if test="${SpringSecurityUtils.ifAllGranted(Roles.ROLE_JOB_ADMIN.toString())}">
            <div class="toolbar">
                <input type="radio" id="radio1" name="radio" onchange="jQuery('#f3').hide(); jQuery('#${job.jobId}_schedule').val(null); jQuery('#f3').submit(); " ${job.schedule ? '' : 'checked=\"checked\"'} /><label for="radio1" >Manual</label>
                <input type="radio" id="radio2" name="radio" onchange="jQuery('#f3').show();" ${job.schedule ? 'checked=\"checked\"' : ''} /><label for="radio2">Cron</label>
            </div>
            <g:formRemote onSuccess="jQuery('#${job.jobId}_schedule').effect('highlight',{color: '#90ee90'},1000);" name="f3" url="[controller: 'job', action: 'updateField', id: job.jobId]" style="${job.schedule ? '' : 'display: none;'}">
                <g:hiddenField name="field" value="schedule"/>
                <input id="${job.jobId}_schedule" class="ui-corner-all" type="text" name="value" value="${job.schedule ?: '0 0 0 0 0 0'}" style="width: 50%;"/>
                <a href="javascript: void();" onclick="jQuery('#f3').submit();" name="submit" value="" href="#" class="btn save" icon="ui-icon-disk"></a>
            </g:formRemote>
        </g:if>
        <g:else>
            <g:if test="${job.schedule}">
                ${job.schedule}
            </g:if>
            <g:else>
                Manual
            </g:else>
        </g:else>
    </div>
    <br/>
    <h2>Properties
        <div class="css_left toolbar">
            <g:if test="${SpringSecurityUtils.ifAllGranted(Roles.ROLE_JOB_ADMIN.toString())}">
                <a class="btn" icon="ui-icon-plus" href="${createLink(controller: 'job', action: 'propertySelect', id: job.jobId)}"></a>
            </g:if>
        </div>
    </h2>
    <div id="propertiesList">
        <g:render template="propertiesTable" model="[job: job]"/>
    </div>
    <br/>
    <h2>Targets
        <div class="css_left toolbar">
            <g:if test="${SpringSecurityUtils.ifAllGranted(Roles.ROLE_JOB_ADMIN.toString())}">
                <a class="btn" icon="ui-icon-plus" href="${createLink(controller: 'job', action: 'targetSelect', id: job.jobId)}"></a>
            </g:if>
        </div>
    </h2>

    <div id="targetsList">
        <g:render template="targetsTable" model="[job: job]"/>
    </div>
    <br/>

    <h2>Notification List</h2>

    <div id="notifiedList">
        <g:render template="notifiedTable" model="[job: job]"/>
    </div>
    <br/>

</div>

</body>
</html>